package cn.cvs.servlet;

import cn.cvs.pojo.Resume;
import cn.cvs.service.ResumeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/Add")
public class AddServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Resume r = new Resume();
        r.setUserName(req.getParameter("userName"));
        r.setSex(req.getParameter("sex"));
        r.setBirth(req.getParameter("birth"));
        r.setAddress(req.getParameter("address"));
        r.setTelephone(req.getParameter("telephone"));
        r.setSchool(req.getParameter("school"));
        r.setStatus(Integer.parseInt(req.getParameter("status")));
        ResumeService service = new ResumeService();
        int count = service.add(r);
        if (count>0){
            out.print("<script>\n" +
                    "      alert(\"添加成功\");\n" +
                    "      location.href='list';\n" +
                    "    </script>");
        }else{
            out.print("<script>\n" +
                    "      alert(\"添加失败\");\n" +
                    "      history.back();\n" +
                    "    </script>");
        }
    }
}
